// pages/buycart/buycart.js
Page({
    /**
     * 页面的初始数据
     */
    data: {
        list: [
            { title: "华为上看到了夫卡了数据分类是否1", type: "0", price: "4894", count: "12", checked: false, id: 1 },
            { title: "华为上看到了夫卡了数据分类是否2", type: "1", price: "4894", count: "12", checked: false, id: 2 },
            { title: "华为上看到了夫卡了数据分类是否3", type: "0", price: "4894", count: "12", checked: false, id: 3 }
        ],
        selectedList: {},//单个选中的列表
        count: 1,
        maxCount: 100,
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
    //选中或取消列表(选择单个的)
    selectList: function (options) {
        var id = options.currentTarget.dataset.id;
        var list = this.data.list;
        var index = options.currentTarget.dataset.index;
        var type = list[index].type;
        this.setData({
            selectedList: { "id": id, "type": type }
        });
    },
    //选中或取消列表(选择多个的)
    selectList1: function (options) {
        var index = options.currentTarget.dataset.index;
        var list = this.data.list;
        list[index].checked = !list[index].checked;
        this.setData({
            list: list
        });
    },
    //打开订单详情页面
    openOrderDetail: function () {
        wx.navigateTo({
            url: '../orderDetail/orderDetail',
        })
    },
    //增加/减少数量
    changeCount: function (options) {
        var type = options.currentTarget.dataset.type;
        var count = this.data.count * 1;
        var maxCount = this.data.maxCount * 1;
        if (type == "reduce") {
            if (count <= 1) {
                count = 1;
            } else {
                count--;
            }
        } else if (type == "add") {
            if (count >= maxCount) {
                count = maxCount;
            } else {
                count++;
            }
        }
        this.setData({
            count: count
        });
    }
})